clear all	
cd "${data}"	

use "data1.dta", clear 

gen rile_rs = ( rile - (-100) ) / ( (100)-(-100) ) * 10

drop if daysafter==.
  
* sometimes the models have issues of convergence, sometimes it doesn't. However, running the models without the country level helps. The interpretation of the results are not influenced by this. We present the results from models without country level, but with country fixed effects. 

eststo CMP_0: mixed IMD3007_ rile_rs i.country_ || election_: || respondent: 
eststo CMP_1: mixed IMD3007_ daysafter rile_rs i.country_ || election_: || respondent: 
eststo CMP_2: mixed c.IMD3007_ c.daysafter##c.rile_rs i.country_ || election_: || respondent: rilelog_rs 

margins, dydx(rile_rs) at(daysafter=(0(30)300)) post
marginsplot, ytitle("AME of a one-unit change in party position", size(3)) recastci(rarea) level(95) recast(line) plot1opts(color() lpattern(shortdash)) title("") addplot(hist daysafter, percent color(gs12%50) yaxis(2) ytitle("percent", size(3) axis(2)) yscale(range(0(5)25) axis(2) alt)) legend(off) xscale(range(0(30)300)) xlabel(0(30)300)
cd "${figures}"
graph save "figureE1.gph", replace
graph export "figureE1.png", replace

  
 cd "${tables}"

  esttab CMP_0 CMP_1 CMP_2 using tableE1.tex ,replace  b(3) se(3) nogap transform(ln*: exp(2*@) 2*exp(2*@))  
  
